Array and Pointer
Q11.
Consider the following declaration : structaddr { char city[10]; char street[30]; int pin; }; struct { char name[30]; int gender; struct addr locate; } person, *kd = &personThen ^{\star}(k d->\text { name }+2) can be used instead of:Q13.
Consider the following C program. #include < stdio.h > struct Ournode{ char x,y,z; }; int main(){ struct Ournode p = {'1', '0','a'+2}; struct Ournode *q = &p printf("%c,%c",*((char*)q+1),*((char*)q+2)); return 0; } The output of this program is:Q14.
Consider the following snippet of a C program. Assume that swap (&x, &y) exchanges the contents of x and y. int main ( ) { int array[]={3,5,1,4,6,2}; int done =0 ; int i ; while (done = = 0) { done = 1; for (i = 0; i <=4; i ++) { if (array [i] < array [i +1]) { swap (& array [i], &array [i+1]); done = 0; } } for (i = 5 ; i > =1; i --) { if (array [i] > array [ i-1]) { swap ( & array [i] , &array [i-1]); done = 0; } } } printf ( " %d " , array [3] ); } The output of the program is ____________.Q15.
Consider the following C program. #include #include void printlength (char *s, char *t) { unsigned int c = 0; int len = ((strlen(s) - strlen (t)) > c) ? strlen(s): strlen(t); printf ("%d\n", len); } void main ( ) { char *x = "abc"; char *y ="defgh"; printlength (x,y); Recall that strlen is defined in string.h as returning a value of type size_t, which is an unsigned int. The output of the program is _____________.Q16.
Consider the following function implemented in C: void printxy (int x, int y) { int *ptr ; x = 0; ptr = &x y = * ptr; * ptr = l; print f ("%d, %d," x, y); } The output of invoking printxy (1,1) isQ17.
What will be output of the following program? Assume that you are running this program in little-endian processor. #include < stdio.h > int main() { short a=320; char *ptr; ptr=(char *)&a printf("%d",*ptr); return 0; }Q18.
Consider the following C code: # include int * assignval (int *x, int val) { *x = val; return x; } void main ( ) { int * x= malloc (sizeof (int)); if (NULL = = x) return; x = assignval (x,0); if(x) { x=(int *) malloc (sizeof (int)); if (NULL = = x) return; x = assignval (x, 10); } printf("%d\n", *x); free (x); } The code suffers from which one of the following problems:Q19.
What is the output of this C code? #include < stdio.h > void main() { int k=5; int *p=&k int **m=&p printf("%d %d %d",k,*p,**m); }Q20.
Consider the following C declaration: struct ( short x[5]; union { float y; long z; } u; )t;Assume that the objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment consideration, is: